package com.ep.modules.app.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ep.common.utils.PageUtils;
import com.ep.modules.app.dao.AppFreightCalculationRulesMapper;
import com.ep.modules.app.entity.AppFreightCalculationRules;
import com.ep.modules.app.entity.AppFreightCalculationRulesExample;
import com.ep.modules.app.entity.AppFreightCalculationRulesWithBLOBs;
import com.ep.modules.app.service.AppFreightCalculationRulesService;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppFreightCalculationRulesServiceImpl implements AppFreightCalculationRulesService {
    @Autowired
    private AppFreightCalculationRulesMapper appFreightCalculationRulesMapper;

    public PageUtils queryPage(Map<String, Object> params) {
        String searchKey = (String)params.get("searchKey");
        Long searchUserId = (Long)params.get("searchUserId");
        AppFreightCalculationRulesExample example = new AppFreightCalculationRulesExample();
        AppFreightCalculationRulesExample.Criteria criteria = example.createCriteria();
        List<AppFreightCalculationRules> list = appFreightCalculationRulesMapper.selectByExample(example);
        Page<AppFreightCalculationRules> page = new Page<>();
        page.setRecords(list);
        return new PageUtils(page);
    }

    public AppFreightCalculationRules getById(Long id) {
        return appFreightCalculationRulesMapper.selectByPrimaryKey(id.intValue());
    }

    public void save(AppFreightCalculationRules entity) {

        // 创建一个 AppFreightCalculationRulesWithBLOBs 对象
        AppFreightCalculationRulesWithBLOBs target = new AppFreightCalculationRulesWithBLOBs();

        // 手动将 AppFreightCalculationRules 的值赋给 AppFreightCalculationRulesWithBLOBs
        target.setRuleId(entity.getRuleId());
        target.setRuleName(entity.getRuleName());
        target.setBillingMethod(entity.getBillingMethod());
        target.setCreatedAt(entity.getCreatedAt());
        target.setUpdatedAt(entity.getUpdatedAt());

        appFreightCalculationRulesMapper.insert(target);
    }

    public void update(AppFreightCalculationRules entity) {

        // 创建一个 AppFreightCalculationRulesWithBLOBs 对象
        AppFreightCalculationRulesWithBLOBs target = new AppFreightCalculationRulesWithBLOBs();

        // 手动将 AppFreightCalculationRules 的值赋给 AppFreightCalculationRulesWithBLOBs
        target.setRuleId(entity.getRuleId());
        target.setRuleName(entity.getRuleName());
        target.setBillingMethod(entity.getBillingMethod());
        target.setCreatedAt(entity.getCreatedAt());
        target.setUpdatedAt(entity.getUpdatedAt());

        appFreightCalculationRulesMapper.updateByPrimaryKeySelective(target);
    }

    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
                appFreightCalculationRulesMapper.deleteByPrimaryKey(id.intValue());
        }
    }
}